unit kfcmdline;

interface
uses vm,classes;

procedure kfmainloop;
procedure init;

var
 engine:TKsanaForthVM;
 outputbuf:string;

implementation

procedure consoleinputcheck(vm:Tksanaforthvm);
begin
  vm.tos:=vm.tos;
end;
procedure consoleztype(vm:Tksanaforthvm;s:pchar);
begin
  outputbuf:=outputbuf+s;
end;


procedure flush;
begin
    writeln( outputbuf);
    outputbuf:='';
end;
procedure consoleemit(vm:Tksanaforthvm;c:char);
begin
  if c=#13 then begin
    flush;
  end else begin
    outputbuf:=outputbuf+c;
  end;
end;

procedure init;
begin
  writeln('Ksana Forth Command Line 2007/9/4');
  engine:=TKsanaForthVM.create;
  engine.interactive:=true;
  engine.tickinputcheck := consoleinputcheck;
  engine.tickztype := consoleztype;
  engine.tickemit := consoleemit;
  engine.reset;
  writeln('init ok');
  engine.reload;
  writeln('softcore loaded');
//  engine.verbose:=true;

  //updatestatus;
end;
procedure kfmainloop;
var
  s:string;
begin
  init;
  repeat
    readln(s);
    engine.eval(s);
    flush;
  until engine.quiting;
  engine.free;
end;



end.